<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Models;
use App\Models\CustomsExporter;
use Illuminate\Http\Request;

// 系统参数接口
class ConfigController extends Controller
{


    public function index()
    {
        $config = [
            'CustomsExporter' => [
                'type'=> Models\CustomsExporter::TYPE,
            ],
            'CustomsHarbour' => [
                'type'=> Models\CustomsHarbour::TYPE,
            ],
        ];
        $config['Contract'] = [
            'TransportType' => Models\Contract::TransportType,
            'status' => Models\Contract::CONTRACT_STATUS_MAP,
            'harb_from' => Models\CustomsHarbour::getFromHarbourList(), // 装运地
            'harb_dest' => Models\CustomsHarbour::getDestHarbourList(), // 卸货地
            'buyer' => Models\CustomsExporter::where('type', Models\CustomsExporter::BUYER)->pluck('name_cn', 'id'),
            'seller' => Models\CustomsExporter::where('type', Models\CustomsExporter::SELLER)->pluck('name_cn', 'id'),
            'currency' => Models\Contract::Currency,
            'from_area' => Models\Suppliers::getCountryByDistinct(), //原厂国
            'dest_area' => Models\CustomsHarbour::getCountryByType(Models\CustomsHarbour::DESC_PORT), //目的国

        ];

        // 格式化
        /*foreach ($config as $cls=>&$group) {
            foreach ($group as &$unit) {
                foreach ($unit as $key=>&$val) {
                    $val = [
                        'key' => $key,
                        'val' => $val,
                    ];
                }
                $unit = array_values($unit);
            }
        }*/

        return $this->resSuccess('', $config);

    }

}
